import Vue from 'vue'
import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory'
const cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper')
const getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject

export default function (group, element, translate) {
  group.entries.push(entryFactory.textField({
    id: 'formDesigner',
    label: translate('FormDesigner'),
    modelProperty: 'formDesigner',
    get: function (element, node) {
      var bo = getBusinessObject(element)
      var formDesigner = bo.get('camunda:formDesigner')

      return {
        formDesigner: formDesigner || Vue.ls.get(`formDesigner:${document.querySelector('#camunda-id').value}`) || ''
      }
    },

    set: function (element, values) {
      var bo = getBusinessObject(element)
      return cmdHelper.updateBusinessObject(element, bo, {
        'camunda:formDesigner': values.formDesigner || Vue.ls.get(`formDesigner:${document.querySelector('#camunda-id').value}`) || undefined
      })
    }
  }))
}
